# 服务端程序
import socket   # 导入socket模块

# 服务器地址信息
addr_info = ('127.0.0.1', 9999)

# 创建socket对象
sv = socket.socket(
    socket.AF_INET,
    socket.SOCK_STREAM,
    socket.IPPROTO_TCP
)

# 绑定地址信息
sv.bind(addr_info)
# 监听客户端的连接
sv.listen()
print('服务器启动成功')

# 接收客户端的连接
client, addr = sv.accept()

while True:
    data = client.recv(1024)
    if not data:
        break
    msg = bytes(data).decode()
    print(f'Client: {msg}')

client.close()
sv.close()